package pers.qianyu.month_202101.date_20210121;

/**
 * 26. 删除排序数组中的重复项
 * https://leetcode-cn.com/problems/remove-duplicates-from-sorted-array/submissions/
 *
 * @author mizzle rain
 * @date 2021-01-21 14:28
 */
public class RemoveDuplicates2 {
    // 另一种双指针解法
    public int removeDuplicates(int[] nums) {
        int len = nums.length;
        if (len < 2) return len;
        int k = 1;
        for (int i = 1; i < len; i++) {
            if (nums[i] != nums[i - 1]) {
                nums[k++] = nums[i];
            }
        }
        return k;
    }
}
